const str = "test message"

/*
(node:13872) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. 
Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
*/

//编码
let encoded = new Buffer.from(str).toString('base64');
console.log(encoded)
//解码
let decoded = new Buffer.from(encoded, 'base64').toString();
console.log(decoded)